package com.yunfangdata.web.controller;

import com.yunfangdata.domain.Applicant;
import com.yunfangdata.query.QueryObject;
import com.yunfangdata.service.IApplicantService;
import com.yunfangdata.util.JsonResult;
import com.yunfangdata.util.PageResult;
import com.yunfangdata.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("applicant")
public class ApplicantController {


    @Autowired
    private IApplicantService applicantService;

    @RequiresPermissions("applicant:index")
    @PermissionName("人才资源库首页")
    @RequestMapping("")
    public String index(){
        return "applicant/list";
    }

    @RequiresPermissions("applicant:list")
    @PermissionName("人才资源库列表")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(QueryObject qo){

        return applicantService.query(qo);
    }

    @RequiresPermissions("applicant:save")
    @PermissionName("人才保存")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Applicant applicant){
        JsonResult result = new JsonResult();
        try {
            applicantService.save(applicant);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("操作失败");
        }
        return result;

    }

    @RequiresPermissions("applicant:admission")
    @PermissionName("人才保存")
    @RequestMapping("admission")
    @ResponseBody
    public JsonResult admission(Long id){
        JsonResult result = new JsonResult();
        try {
            applicantService.admission(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("操作失败");
        }
        return result;

    }

    @RequiresPermissions("applicant:disAdmission")
    @PermissionName("人才被干掉")
    @RequestMapping("disAdmission")
    @ResponseBody
    public JsonResult disAdmission(Long id){
        JsonResult result = new JsonResult();
        try {
            applicantService.disAdmission(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("操作失败");
        }
        return result;

    }













}
